﻿@using CodeCamp.Models.Schedule
@using CodeCamp.Models.Shared
@using CodeCamp.Infrastructure.Extensions
@model ScheduleRoomsViewModel
@{
    ViewBag.Title = "";
    string headline;
    if ((@Model != null) && (@Model.EventDisplayName != null))
    {
        ViewBag.Title = @Html.Encode(@Model.EventDisplayName + " | Schedule by Room");
        headline = @Model.EventDisplayName + " Schedule by Room";
    }
    else
    {
        ViewBag.Title = "Code Camp | Schedule by Room";
        headline = "Code Camp Schedule by Room";
    }
}

@if (Model.ScheduleIsPublic)
{
<h2>@headline</h2>
}
else
{
<h2>@headline - NOT YET PUBLIC</h2>
}

<p>
    View the @Html.ActionLink("Agenda", "Agenda", new { eventName = Model.EventShortName }) to see @Model.EventDisplayName at a glance.
    View the @Html.ActionLink("Session Schedule", "Index", new { eventName = Model.EventShortName }) to see the schedule arranged chronologically.
</p>
<p>
    Details are subject to change. But you already knew that.
</p>

<h3>@Model.EventStartDate.ToLongDateString()</h3>

@if (Model.ScheduleIsPublic || Model.ScheduleInsider || Model.ScheduleVisibleForPresenter)
{
<table class="scheduleByRoom">
    <tr class="horizontalLayout">
      <td class="col1"></td>
      <td class="col2"></td>
      <td class="col3"></td>
      <td class="col4"></td>
    </tr>

    @foreach (var building in Model.Buildings)
    {
        foreach (var room in building.Rooms)
        {
            <tr class="roomRow">
                <td colspan="4">@Html.ActionLink(string.Format("{0}, {1} {2}", building.Name, room.Name, room.RoomInfo), "Room", new { eventName = Model.EventShortName, id = room.RoomId })</td>
            </tr>
            foreach (var session in room.Sessions.OrderBy(s => s.StartTime))
            {
                <tr class="sessionRow">
                    <td></td>
                    <td class="time">@session.StartTime.ToShortTimeString() &ndash;
                        @session.EndTime.ToShortTimeString()
                    </td>
                    <td class="session">@Html.ActionLink(session.Title, "Details", "Sessions", new { eventName = Model.EventShortName, id = session.SessionId }, null)</td>
              <td class="presenters">
            @{
                var first = true;
                foreach(var presenter in session.Presenters)
                {
                    if (!first) { <text>, </text> }
                    else { first = false; }
                    @Html.ActionLink(presenter.Name, "Details", "Presenters", new { eventName = Model.EventShortName, id = presenter.PresenterId}, null)
                }
            }
              </td>
                </tr>
            }
        }
    }
</table>
}

@section sidebar {
    @Html.Partial("SidebarCommonPartial")
}
